package org.example;

import lombok.extern.slf4j.Slf4j;
import org.example.utils.IdWorker;
import org.example.utils.RedisUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.Random;


@Slf4j
@SpringBootApplication  //标记这是Spring Boot应用的主类
public class BlogApplication {
    public static void main(String[] args) {    //main方法：应用启动入口，使用SpringApplication.run()启动Spring容器
        log.info("Spring Boot Application Started");
        SpringApplication.run(BlogApplication.class, args);
    }

    /**
     * @return
     * @Bean 将方法返回值注册为Spring Bean
     * Spring容器会管理这个IdWorker实例
     * 其他组件可以通过依赖注入使用这个Bean
     */
    @Bean
    public IdWorker createIdWorker() {
        return new IdWorker(0, 0);
    }

    //加密密码
    @Bean
    public BCryptPasswordEncoder createPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public RedisUtil createRedisUtil() {
        return new RedisUtil();
    }

    @Bean
    public Random createRandom() {
        return new Random();
    }
}